﻿using HandyControl.Controls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace HMI.View
{
    /// <summary>
    /// WinItem.xaml 的交互逻辑
    /// </summary>
    public partial class WinItem : UserControl
    {
        public WinItem()
        {
            InitializeComponent();
        }
        public int Index { get; set; }
        public string Header
        {
            get { return Convert.ToString(Titlex.Content); }
            set { Titlex.Content = value; }
        }
        public string Description
        {
            get { return Convert.ToString(Filex.Content); }
            set { Filex.Content = value; }
        }
        public void FillData(ProjectModel prom)
        {
            Header = prom.Name;
            Description = prom.Description;
        }
        private bool selected = false;
        public bool Selected
        {
            get { return selected; }
            set
            {
                if (value)
                {
                    SolidColorBrush brushbk = FindResource("yes") as SolidColorBrush;
                    gd.Background = brushbk;
                    selected = true;
                    IconID = -1 * Math.Abs(IconID);
                }
                else
                {
                    SolidColorBrush brushbk = FindResource("no") as SolidColorBrush;
                    gd.Background = brushbk;
                    selected = false;
                    IconID = Math.Abs(IconID);

                }
            }
        }
        private int iconID = 1;
        public int IconID
        {
            get
            {
                return iconID;
            }
            set
            {
                string IcoStr = "";
                switch (value)
                {
                    case 1:
                        IcoStr = "HomeEmpty";
                        break;
                    case 2:
                        IcoStr = "TaskEmpty";
                        break;
                    case 3:
                        IcoStr = "SetupEmpty";
                        break;
                    case 4:
                        IcoStr = "DevEmpty";
                        break;
                    case 5:
                        IcoStr = "LogEmpty";
                        break;
                    case 6:
                        IcoStr = "UserEmpty";
                        break;

                    case -1:
                        IcoStr = "HomeFull";
                        break;
                    case -2:
                        IcoStr = "TaskFull";
                        break;
                    case -3:
                        IcoStr = "SetupFull";
                        break;
                    case -4:
                        IcoStr = "DevFull";
                        break;
                    case -5:
                        IcoStr = "LogFull";
                        break;
                    case -6:
                        IcoStr = "UserFull";
                        break;
                }
                Geometry geometry = (Geometry)Application.Current.Resources[IcoStr];
                IconElement.SetGeometry(icos, geometry);
                iconID = value;
            }
        }
        public Action<ProjectModel> ClickItem { get; set; }
        private void Icos_Down(object sender, MouseButtonEventArgs e) {
            if (ClickItem != null)
            {
                ProjectModel model = new ProjectModel();
                model.Index = Index;
                model.Name = Name;
                model.Description = Description;
                ClickItem(model);
            }
        }

    }
}
